<!--
 * @Version: 1.0
 * @Date: 2021-04-08 19:48:26
 * @LastEditTime: 2022-01-12 18:04:54
 * @Description:
-->
<template>
  <el-card class="app-container">
    <div>
      <!-- <div class="header_title_box">
        <h2>发货单管理</h2>
      </div> -->
      <div>
        <form-selections :is-active="isActive" :items="formItems" :query-param.sync="queryParam" display="block" @handleSearch="handleSearch" />
      </div>
    </div>
    <el-tabs v-model="delivery_tabs" style="margin-top:10px" type="card" @tab-click="handleClick">
      <el-tab-pane label="未打印发货单" name="1" :disabled="loading" />
      <el-tab-pane label="已打印发货单" name="2" :disabled="loading" />
      <el-tab-pane label="第三方发货单" name="3" :disabled="loading" />
    </el-tabs>
    <div class="select_flex" style="margin-top:-10px">
      <div v-show="delivery_tabs==='1'" class="operation_button_box">
        <el-button v-action="'deliveryOrder@delivery'" size="small" :disabled="selectedCodes.length>0?false:true" type="success" icon="el-icon-circle-plus" @click="getLogistics">获取物流单号</el-button>
        <el-button v-action="'deliveryOrder@getLabel'" size="small" :disabled="selectedCodes.length>0?false:true" type="success" icon="el-icon-circle-plus" @click="deliveryGetLabelMore('UPS')">批量打印UPS订单</el-button>
        <el-button v-action="'deliveryOrder@getLabelAll'" size="small" :disabled="selectedCodes.length>0?false:true" type="success" icon="el-icon-circle-plus" @click="deliveryGetLabelMore('USPS')">批量打印USPS订单</el-button>
        <el-button v-action="'deliveryOrder@importDeliverOrder'" size="small" type="primary" @click="formVisibleDown=true">导出发货单</el-button>
        <el-button v-action="'deliveryOrder@importLogisticsOrder'" size="small" type="primary" @click="formVisibleFile=true;importUrl='/deliveryOrders/importLogisticsOrder'">导入物流信息</el-button>
        <el-button v-action="'deliveryOrder@orderSynchronous'" size="small" :disabled="selectedCodes.length>0?false:true" type="success" icon="el-icon-circle-plus" @click="orderSynchronous">同步物流信息</el-button>
        <el-button v-action="'deliveryOrder@confirmDeliverBatch'" size="small" :disabled="selectedCodes.length>0?false:true" type="success" icon="el-icon-circle-plus" @click="confirmDeliverBatch">批量确认发货单</el-button>
        <!-- deliveryOrder@confirmDeliverBatch -->
      </div>
      <div v-show="delivery_tabs==='2'" class="operation_button_box">
        <el-button v-action="'deliveryOrder@importDeliverOrder'" size="small" type="success" icon="el-icon-download" @click="formVisibleDown=true">导出发货单</el-button>
        <el-button v-action="'deliveryOrder@importPickOrder'" size="small" type="primary" icon="el-icon-download" @click="formVisibleDown2=true">导出拣货单</el-button>
        <el-button v-action="'deliveryOrder@orderSynchronous'" size="small" :disabled="selectedCodes.length>0?false:true" type="success" icon="el-icon-circle-plus" @click="orderSynchronous">同步物流信息</el-button>
        <!-- <el-button
            v-action="'deliveryOrder@deliveryExport'"
            size="middle"
            type="primary"
            icon="el-icon-download"
          >导出出货单</el-button> -->
        <el-button v-action="'deliveryOrder@getLabel'" size="small" :disabled="selectedCodes.length>0?false:true" type="success" icon="el-icon-circle-plus" @click="deliveryGetLabelMore('UPS')">批量打印UPS订单</el-button>
        <el-button v-action="'deliveryOrder@getLabelAll'" size="small" :disabled="selectedCodes.length>0?false:true" type="success" icon="el-icon-circle-plus" @click="deliveryGetLabelMore('USPS')">批量打印USPS订单</el-button>
      </div>
      <div v-show="delivery_tabs==='3'" class="operation_button_box">
        <el-button v-action="'deliveryOrder@getLabel'" size="small" :disabled="selectedCodes.length>0?false:true" type="success" icon="el-icon-circle-plus" @click="deliveryGetLabelMore('UPS')">批量打印UPS订单</el-button>
        <el-button v-action="'deliveryOrder@getLabelAll'" size="small" :disabled="selectedCodes.length>0?false:true" type="success" icon="el-icon-circle-plus" @click="deliveryGetLabelMore('USPS')">批量打印USPS订单</el-button>
        <el-button v-action="'deliveryOrder@importLogisticsOrderNo'" size="small" type="primary" @click="formVisibleDown3=true">导出第三方发货单</el-button>
        <el-button v-action="'deliveryOrder@exportThirdPartOrder'" size="small" type="primary" @click="formVisibleFile=true;importUrl='/deliveryOrders/importLogisticsOrderNo'">导入物流信息</el-button>
        <!-- <el-button
          v-action="'deliveryOrder@updateLogisticsType'"
          :disabled="selectedIds && selectedIds.length<1 && selectTypeLoginstics===-1"
          size="middle"
          type="primary"
          @click="setLogisticsType(selectedIds)"
        >设置发货类型</el-button> -->
        <el-button v-action="'deliveryOrder@updateLogisticsType'" size="small" :disabled="selectedCodes.length>0?false:true" type="primary" @click="setLogisticsTypeMore(selectedIds)">设置发货类型
        </el-button>
        <el-button v-action="'deliveryOrder@delivery'" size="small" :disabled="selectedCodes.length>0?false:true" type="success" @click="getLogisticsThrid">获取物流单号</el-button>
        <el-button v-action="'deliveryOrder@orderSynchronous'" size="small" :disabled="selectedCodes.length>0?false:true" type="success" @click="orderSynchronous">同步物流信息</el-button>
        <el-button v-action="'deliveryOrder@confirmDeliverBatch'" size="small" :disabled="selectedCodes.length>0?false:true" type="success" @click="confirmDeliverBatch">批量确认发货单</el-button>
        <el-button v-action="'deliveryOrder@batchThridOrderDeliver'" size="small" :disabled="selectedCodes.length>0?false:true" type="success" @click="batchThridOrderDeliver">批量收货</el-button>
      </div>
      <div class="select_button_box">
        <el-button size="small" type="primary" class="filter-item search" icon="el-icon-search" @click="handleSearch">
          搜索
        </el-button>
        <el-button size="small" class="filter-item" icon="el-icon-refresh" @click="handleRefresh">
          重置
        </el-button>
        <el-button size="small" @click="isActive=!isActive">{{ isActive?'展开':'收起' }}
        </el-button>
      </div>
    </div>

    <el-table ref="multipleTable" v-loading="loading" :row-class-name="tableRowClassName" :data="data" tooltip-effect="dark" :max-height="screenHeigh" border fit row-key="id" @selection-change="handleSelectMulti">
      <el-table-column type="selection" width="55" align="center" />
      <!-- <el-table-column label="序号" type="index" width="55" align="center" /> -->
      <!-- <el-table-column
        type="selection"
        width="55"
        align="center"
        :selectable="checkSelectable"
      /> -->
      <el-table-column align="center" label="操作" min-width="200" fixed>
        <template slot-scope="sales">
          <span v-if="sales.row.status===0&&sales.row.delivery_state!==6">
            <el-button v-action="'deliveryOrder@confirmDeliver'" class="operate_style blue" type="text" @click="formVisible=true;orderId=sales.row.id+''">确认发货单</el-button>
          </span>

          <el-button v-if="sales.row.delivery_state!==6 && (delivery_tabs ==='2' || ((sales.row.delivery_process_status === 1 || delivery_tabs ==='3') && sales.row.shipping_code!==''&&sales.row.logistics_type === 1))" v-action="'deliveryOrder@getLabelAll'" size="middle" type="text" class="operate_style" @click="deliveryGetLabel(sales.row)">打印物流面单</el-button>
          <el-button v-if="sales.row.delivery_state!==6 &&sales.row.status===1 && sales.row.shipping_code ===''" v-action="'deliveryOrder@updateAddress'" class="operate_style blue" type="text" @click="formVisibleAddress=true;orderId=sales.row.id+'';">修改地址</el-button>
          <el-button v-if="delivery_tabs==='3' && sales.row.shipping_code ===''&&sales.row.delivery_state!==6" class="operate_style blue" type="text" @click="setLogisticsType(sales.row)">设置发货类型</el-button>
          <el-button v-if="sales.row.order_type_source == 1&& sales.row.delivery_state!==6 && sales.row.delivery_state!==5 && sales.row.delivery_process_status===1 " v-action="'deliveryOrder@voidOrder'" class="delete_style" type="text" @click="viodButtom(sales.row)">作废
          </el-button>
          <!-- <el-button
            v-if="delivery_tabs==='2' && ( sales.row.delivery_state !==5 && sales.row.delivery_state !==6 )"
            v-action="'deliveryOrder@delOrderPrinted'"
            type="text"
            class="delete_style"
            @click="delOrderPrinted(sales.row.id, sales.row.invoice_no)"
          >
            作废
          </el-button> -->
          <span v-if="delivery_tabs==='2' && ( sales.row.delivery_state !==5 && sales.row.delivery_state !==6 )" v-action="'deliveryOrder@delOrderPrinted'">
            <el-popover placement="top" width="180" title="操作">
              <div style="margin: 0;width: 200px">
                <el-button type="primary" icon="el-icon-edit" size="mini" @click="delOrderPrinted(sales.row.id, sales.row.invoice_no, '2')">收货</el-button>
                <el-button size="mini" icon="el-icon-delete" type="danger" @click="delOrderPrinted(sales.row.id, sales.row.invoice_no, '1')">作废</el-button>
              </div>
              <el-button slot="reference" type="text" class="delete_style" style="margin-right: 2px;">作废</el-button>
            </el-popover>
          </span>

        </template>
      </el-table-column>
      <el-table-column align="center" prop="invoice_no" label="发货单号" width="150">
        <template slot-scope="scope">
          <span class="blue pointer" @click="formVisibleInfo=true;orderId=scope.row.id+'';title='发货订单详情'">{{ scope.row.invoice_no }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="订单类型" sortable prop="order_delivery_type" width="110">
        <template slot-scope="scope">
          <!-- // 1-整单发货 2-拆分发货 -->
          {{ scope.row.order_delivery_type === 1 ? '整单发货' : '拆分发货' }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="是否同步" sortable prop="order_type_source" width="110">
        <template slot-scope="scope">
          <!-- // 1-整单发货 2-拆分发货 -->
          {{ scope.row.sync_logistics === 1 ? '是' : '否' }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="订单来源" sortable prop="order_type_source" width="110">
        <template slot-scope="scope">
          <!-- // 1-整单发货 2-拆分发货 -->
          {{ scope.row.order_type_source === 1 ? '正常' : '补货' }}
        </template>
      </el-table-column>
      <el-table-column align="center" prop="order_type" label="原订单类型" width="100">
        <template slot-scope="scope">
          {{ scope.row.order_type===3 ? '客户订单' : scope.row.order_type===4?'预售订单': scope.row.order_type===2? '借卖订单': '销售订单' }}
        </template>
      </el-table-column>
      <el-table-column align="center" prop="code_goods" label="商品编码" min-width="180">
        <template slot-scope="scope">
          {{ scope.row.after_order_id ? scope.row.goods_code : scope.row.code_goods }}
        </template>
      </el-table-column>
      <el-table-column align="center" prop="number" sortable label="发货数量" width="110" />
      <el-table-column align="center" prop="goods_group_name" label="多箱分组" min-width="210" show-overflow-tooltip />
      <el-table-column align="center" prop="address_stateorprovince" label="买家州" show-overflow-tooltip />
      <el-table-column align="center" prop="vi_name" label="虚拟仓库" width="150" show-overflow-tooltip />
      <el-table-column align="center" prop="en_name" label="实体仓库" width="180" show-overflow-tooltip />
      <el-table-column align="center" label="物流类型" prop="logistics_type">
        <template slot-scope="scope">
          <!-- // 1-整单发货 2-拆分发货 0-未设置 1-自有物流 2-它有物流-->
          {{ scope.row.logistics_type === 1 ? '自有物流' : (scope.row.logistics_type === 2 ? '它有物流' : '未设置') }}
        </template>
      </el-table-column>
      <el-table-column align="center" prop="company_id" label="客户id" />
      <el-table-column align="center" prop="order_no" label="订单编号" width="150" />
      <el-table-column align="center" prop="name_ch" label="商品名称" show-overflow-tooltip />
      <el-table-column align="center" label="Zone" prop="zone" />
      <el-table-column align="center" prop="platform_no" label="平台订单编号" width="180" show-overflow-tooltip />
      <!-- platform_no_ext -->
      <el-table-column align="center" prop="platform_no_ext" label="平台订单编号2" width="180" show-overflow-tooltip />
      <el-table-column align="center" prop="status" label="审核状态">
        <template slot-scope="scope">
          <!-- 0-未确认发货单，1-以确认发货单，2获取物流单号，3打印物流面单 -->
          {{ scope.row.status===0?'待审核':'审核通过' }}
        </template>
      </el-table-column>
      <el-table-column align="center" prop="delivery_process_status" sortable label="订单状态" width="120">
        <template slot-scope="scope">
          {{ orderStatus[scope.row.delivery_state] }}
        </template>
      </el-table-column>
      <el-table-column align="center" prop="shop_name" label="店铺名称" />
      <el-table-column align="center" prop="platform" label="平台" width="120" />
      <el-table-column align="center" prop="shipping_name" label="物流公司" width="150" />
      <el-table-column align="center" prop="shipping_code" label="物流单号" width="210" />
      <el-table-column align="center" prop="category_name" label="分类名称" show-overflow-tooltip>
        <template slot-scope="scope">{{ scope.row.parent_name }}-{{ scope.row.category_name_real }}</template>
      </el-table-column>
      <el-table-column align="center" prop="address_name" label="买家姓名" show-overflow-tooltip />
      <el-table-column align="center" prop="address_email" label="买家邮箱" show-overflow-tooltip />
      <el-table-column align="center" prop="address_cityname" label="买家城市" show-overflow-tooltip />
      <el-table-column align="center" prop="creator_name" label="创建人" width="150" show-overflow-tooltip />
      <el-table-column align="center" prop="created_at" sortable label="创建时间" width="165" />
      <el-table-column align="center" prop="update_name" label="审核人" width="120" show-overflow-tooltip />
      <el-table-column align="center" prop="updated_at" sortable label="审核时间" width="165" />
    </el-table>
    <el-pagination v-if="paginate.total > 0" class="pagination_box" background :current-page="paginate.current" :page-sizes="[50,100,200,500]" :page-size="queryParam.limit" layout="total, sizes, prev, pager, next, jumper" :total="paginate.total" @size-change="handleSizeChange" @current-change="handleCurrentChange" />
    <div>
      <!-------- 回到顶部 ------------>
      <el-backtop :visibility-height="60">
        <i class="el-icon-caret-top" />
      </el-backtop>
    </div>
    <!-- 确认发货单详情 -->
    <DeliveryOrderInfo :id="orderId" :form-visible.sync="formVisible" @handleSearch="handleSearch" />
    <!-- 获取物流单号 -->
    <el-dialog title="获取物流单号" center :visible.sync="formVisibleWl" width="40%" @close="handleCancelWl">
      <el-form :ref="formName" :model="formFieldsData" :rules="rules">
        <el-form-item label="选择物流公司：" :label-width="formLabelWidth" prop="type">
          <el-select v-model="formFieldsData.type" placeholder="选择物流公司" @change="selsectType">
            <el-option v-for="item in companyOption" :key="item.id" :label="item.name" :value="item" />
          </el-select>
        </el-form-item>
        <el-form-item label="已选择发货单">
          <div>{{ selectedCodes }}</div>
        </el-form-item>
        <!--  -->
        <el-form-item label="符合条件发货单">
          <div>{{ selectedCodesNew }}</div>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="handleCancelWl()">取 消</el-button>
        <el-button :disabled="isbtn" :loading="isbtn" type="primary" @click="deliveryUps">确 定</el-button>
      </div>
    </el-dialog>
    <!-- 详情 -->
    <OrderInfo :id="orderId" :form-visible-down.sync="formVisibleInfo" :title="title" />
    <!-- 打印物流面单 -->
    <el-dialog title="打印物流面单" center :visible.sync="formVisibleWlmd" width="750px" @close="handleCancelWlmd">
      <div v-loading="loadingFaceSheet">
        <div v-if="urlImage && shippingType==='UPS'">
          <div style="height:480px;position: relative;text-align:cenetr;">
            <el-image class="imag_rote" :src="urlImage" fit="cover" />
          </div>
          <div style="text-align:center;margin-top: 50px;position: absolute;bottom: 80px;left:50%;transform: translateX(-50%);width: 100%;">
            <el-button type="primary" @click="savePdf">预 览</el-button>
            <el-button v-if="delivery_tabs!=='2'" v-action="'deliveryOrder@printLabel'" type="primary" :loading="isbtn" @click="submitFormPrint">预览并确认打印</el-button>
            <el-button type="primary" @click="submitFormBatchDown">批量下载Zip</el-button>
            <el-button @click="handleCancelWlmd">取 消</el-button>
          </div>
          <div v-if="delivery_tabs==='1'" style="width60%;position: absolute;left:50%;transform: translateX(-50%);color:red;bottom: 20px;">
            注：预览并确认打印操作后，对应发货单将进入已打印发货单列表，预览操作后，对应发货单不会进入已打印发货单列表
          </div>
        </div>
        <div v-if="urlImage && shippingType==='USPS'">
          <div style="height:480px;position: relative;text-align:center;">
            <el-image class="imag_rote_usps" :src="urlImage" fit="cover" />
          </div>
          <div style="text-align: center;margin-top: 50px;position: absolute;bottom: 80px;left:50%;transform: translateX(-50%);width: 100%;">
            <el-button type="primary" @click="savePdf">预 览</el-button>
            <el-button v-if="delivery_tabs!=='2'" v-action="'deliveryOrder@printLabel'" type="primary" :loading="isbtn" @click="submitFormPrint">预览并确认打印</el-button>
            <el-button type="primary" @click="submitFormBatchDown">批量下载Zip</el-button>
            <el-button @click="handleCancelWlmd">取 消</el-button>
          </div>
          <div v-if="delivery_tabs==='1'" style="width60%;position: absolute;left:50%;transform: translateX(-50%);color:red;bottom: 20px;">
            注：预览并确认打印操作后，对应发货单将进入已打印发货单列表，预览操作后，对应发货单不会进入已打印发货单列表
          </div>
        </div>
        <div v-if="urlImages.length && shippingType==='UPS'" style="height:540px;position: relative;">
          <el-carousel trigger="click" height="450px" :autoplay="false">
            <el-carousel-item v-for="(item,index) in urlImages" :id="'printDiv' + index" :key="item">
              <el-image class="imag_rotes" :src="item" fit="cover" />
            </el-carousel-item>
          </el-carousel>
          <div style="text-align: center;margin-top: 50px;position: absolute;bottom: 60px;left:50%;transform: translateX(-50%);width: 100%;">
            <el-button type="primary" @click="savePdf2">预 览</el-button>
            <el-button v-if="delivery_tabs!=='2'" v-action="'deliveryOrder@printLabel'" type="primary" :loading="isbtn" @click="submitFormPrint">
              预览并确认打印</el-button>
            <el-button type="primary" @click="submitFormBatchDown">批量下载Zip</el-button>
            <el-button @click="handleCancelWlmd">取 消</el-button>
          </div>
          <div v-if="delivery_tabs==='1'" style="width:60%;position: absolute;left:50%;transform: translateX(-50%);color:red;bottom:0">
            注：预览并确认打印操作后，对应发货单将进入已打印发货单列表，预览操作后，对应发货单不会进入已打印发货单列表
          </div>
        </div>
        <div v-if="urlImages.length && shippingType==='USPS'" style="text-align:center;height:540px;position: relative;">
          <el-carousel trigger="click" height="450px" :autoplay="false">
            <el-carousel-item v-for="(item,index) in urlImages" :id="'printDiv' + index" :key="item">
              <el-image class="imag_rote_usps" :src="item" fit="cover" />
              <!-- :src="item" -->
            </el-carousel-item>
          </el-carousel>
          <div style="text-align: center;margin-top: 50px;position: absolute;bottom: 60px;left:50%;transform: translateX(-50%);width: 100%;">
            <el-button type="primary" @click="savePdf2">预 览</el-button>
            <el-button v-if="delivery_tabs!=='2'" v-action="'deliveryOrder@printLabel'" type="primary" :loading="isbtn" @click="submitFormPrint">
              预览并确认打印</el-button>
            <el-button type="primary" @click="submitFormBatchDown">批量下载Zip</el-button>
            <!-- @click="submitFormPrint" -->
            <el-button @click="handleCancelWlmd">取 消</el-button>
          </div>
          <div v-if="delivery_tabs==='1'" style="width:60%;position: absolute;left:50%;transform: translateX(-50%);color:red;bottom:0">
            注：预览并确认打印操作后，对应发货单将进入已打印发货单列表，预览操作后，对应发货单不会进入已打印发货单列表
          </div>
        </div>

      </div>
    </el-dialog>
    <!--发货单下载字段选择-->
    <DownModul url="/deliveryOrders/importDeliverOrder" :search-param="downLoadParam" :form-visible-down.sync="formVisibleDown" :titel="title" :options-modul="optionsModul" />
    <!-- 拣货单 -->
    <DownModul url="/deliveryOrders/importPickOrder" :search-param="downLoadParam" :form-visible-down.sync="formVisibleDown2" :titel="title" :options-modul="optionsModul2" />
    <!-- 拣货单 -->
    <DownModul url="/deliveryOrders/exportThirdPartOrder" :search-param="downLoadParam" :form-visible-down.sync="formVisibleDown3" :titel="title" :options-modul="optionsModul3" />
    <!-- 导人 -->
    <ImportDialog :url="importUrl" title="导入第三方物流" :form-visible.sync="formVisibleFile" @download="downLoad" @handleRefresh="handleRefresh" />
    <!-- 设置发货类型 -->
    <el-dialog title="设置发货物流类型" :visible.sync="formVisibleWLogistics" width="600px" @close="handleCancelLogistics">
      <el-form ref="ruleForm" :model="ruleForm" :rules="rules1" label-width="150px">
        <el-form-item label="已选择发货单">
          <div>{{ selectedCodes }}</div>
        </el-form-item>
        <el-form-item label="请选择发货物流类型" prop="type">
          <el-radio-group v-model="ruleForm.type">
            <el-radio label="1">自有物流</el-radio>
            <el-radio label="2">它有物流</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
      <div style="text-align: center;margin: 30px 0;">
        <el-button type="primary" :loading="isbtnLogistics" @click="submitFormLogistics('ruleForm')">保存</el-button>
        <el-button @click="handleCancelLogistics">取消</el-button>
      </div>
    </el-dialog>
    <!-- 修改地址 -->
    <updateAddress :id="orderId" :form-visible.sync="formVisibleAddress" title="修改地址" />
  </el-card>
</template>

<script>
import FormSelections from '@/components/FormSelection'
import formOperate from '@/layout/mixin/formOperate'
import {
  action
} from '@/directive/permission/index.js' // 权限判断指令
import {
  lforwarderData
} from '@/utils/publicData'
import DeliveryOrderInfo from '../compontent/info.vue'
import OrderInfo from './info/index.vue'
import DownModul from '@/components/DownModul/index.vue'
import ImportDialog from '@/components/importDialog/index.vue'
import { downloadxlsx } from '@/utils/index'
import {
  downloadStream
} from '@/utils/index'
// import { downTemplate } from '@/utils/index.js'
import {
  downloadUrl
} from '@/utils/index'
// import PrintFace from '../compontent/printFace.vue'
// import { jsPDF } from 'jspdf'
// import print from 'vue-print-nb'
import updateAddress from '../compontent/updateAddress.vue'
export default {
  name: 'DeliveryOrder',
  components: {
    DeliveryOrderInfo,
    OrderInfo,
    DownModul,
    FormSelections,
    ImportDialog,
    updateAddress
    // PrintFace
  },
  directives: {
    action
  },
  mixins: [formOperate],
  data() {
    return {
      shippingType: '',
      formVisibleAddress: false,
      otherHeight: 450,
      secondUrl: 1, // 二级路由
      pdfData: '',
      importUrl: '',
      isbtnLogistics: false,
      idsLogistics: [],
      // selectTypeLoginstics: -1,
      ruleForm: {
        type: ''
      },
      formVisibleWLogistics: false,
      formVisibleFile: false,
      searchClass: 1,
      searchShop: 1,
      formItems: [{
        label: '订单状态',
        key: 'delivery_state',
        type: 'select',
        options: [{
          label: '待发货',
          value: '1'
        },
        {
          label: '待打印面单',
          value: '2'
        },
        {
          label: '运输中',
          value: '3'
        },
        {
          label: '配送中',
          value: '4'
        },
        {
          label: '已收货',
          value: '5'
        },
        {
          label: '已作废',
          value: '6'
        }
        ],
        placeholder: '请选择订单状态'
      },
      {
        label: '打印面单时间',
        key: 'datePrint',
        type: '',
        // valueFormat: 'timestamp',
        valueFormat: 'yyyy-MM-dd HH:mm:ss',
        placeholder: '请选择时间范围'
        //   wrap: true
      },
      {
        label: '物流单号',
        key: 'shipping_code',
        type: 'input',
        placeholder: '请输入物流单号'
      },
      {
        label: '快递公司',
        key: 'shipping_name',
        type: 'input',
        placeholder: '请输入快递公司'
      },

      {
        label: '发货单号',
        key: 'invoice_no',
        type: 'input',
        placeholder: '请输入发货单编号'
      },
      {
        label: '订单编号',
        key: 'order_no',
        type: 'input',
        placeholder: '请输入订单编号'
      },
      {
        label: '平台编号',
        key: 'platform_no',
        type: 'input',
        placeholder: '请输入平台编号'
      },
      // {
      //   label: '店铺名称',
      //   key: 'shop_name',
      //   type: 'select',
      //   placeholder: '请输入店铺名称',
      //   filterable: true,
      //   options: []
      // },
      {
        label: '店铺',
        key: 'shop_id',
        type: 'select',
        multiple: true,
        filterable: true,
        placeholder: '请选择店铺',
        options: []
      },
      {
        label: '商品编码',
        key: 'goods_code',
        type: 'input',
        placeholder: '请输入商品编码'
      },
      {
        label: '创建时间',
        key: 'dateCreat',
        type: '',
        valueFormat: 'yyyy-MM-dd HH:mm:ss',
        placeholder: '请选择时间范围'
        //   wrap: true
      },
      {
        label: '虚拟仓库',
        key: 'vi_name',
        type: 'input',
        placeholder: '请输入虚拟仓库'
      },
      {
        label: '实体仓库',
        key: 'en_name',
        type: 'input',
        placeholder: '请输入实体仓库'
      },
      {
        label: '中文名称',
        key: 'goods_name',
        type: 'input',
        placeholder: '请输入商品中文名称'
      },
      {
        label: '商品分类',
        key: 'category_ids',
        type: 'cascader',
        cLabel: 'lable',
        cValue: 'value',
        options: []
      },
      {
        label: '平台名称',
        key: 'platform_name',
        type: 'input',
        placeholder: '请输入平台名称'
      },
      {
        label: '订单来源',
        key: 'type',
        type: 'select',
        placeholder: '请选择订单来源',
        options: [{
          label: '正常订单',
          value: '1'
        },
        {
          label: '补货订单',
          value: '2'
        }
        ]
      },
      {
        label: '订单类型',
        key: 'order_delivery_type',
        type: 'select',
        placeholder: '请选择订单类型',
        options: [{
          label: '整单发货',
          value: '1'
        },
        {
          label: '拆分发货',
          value: '2'
        }
        ]
      },
      {
        label: '买家州/省',
        key: 'stateorprovince',
        type: 'input',
        placeholder: '请输入买家州名'
      },
      {
        label: '买家城市',
        key: 'cityname',
        type: 'input',
        placeholder: '请输入城市'
      },
      {
        label: '买家姓名',
        key: 'user_name',
        type: 'input',
        placeholder: '请输入买家姓名'
      },
      {
        label: '买家邮箱',
        key: 'email',
        type: 'input',
        placeholder: '请输入买家邮箱'
      },
      {
        label: '是否同步',
        key: 'sync_logistics',
        type: 'select',
        placeholder: '请选择',
        options: [{
          label: '是',
          value: '1'
        },
        {
          label: '否',
          value: '0'
        }
        ]
      }
      ],
      downloadxlsxUrl: '',
      formVisibleDown: false,
      formVisibleDown3: false,
      optionsModul3: [{
        key: 'invoice_no',
        label: '发货单编号'
      },
      {
        key: 'shipping_code',
        label: '运单号'
      },
      {
        key: 'goods_code',
        label: 'SKU商品编码'
      },
      {
        key: 'quantity_purchased',
        label: '数量1/Quantity'
      },
      {
        key: 'shop_name',
        label: '店铺名称'
      },
      {
        key: 'en_name',
        label: '实体仓库'
      },
      {
        key: 'vi_name',
        label: '虚拟仓库'
      },
      {
        key: 'address_name',
        label: '收件人姓名/Consignee Name'
      },
      {
        key: 'address_phone',
        label: '收件人电话/Consignee Phone'
      },
      {
        key: 'address_street1',
        label: '街道/Street'
      },
      {
        key: 'address_cityname',
        label: '城市/City'
      },
      {
        key: 'address_stateorprovince',
        label: '州/Province'
      },
      {
        key: 'address_postalcode',
        label: '邮编/Zip Code'
      },
      {
        key: 'address_country_name',
        label: '收件人国家/Consignee Country'
      },
      {
        key: 'platform_no',
        label: '平台订单编码'
      },
      {
        key: 'platform_no_ext',
        label: '平台订单编码2'
      }
      ],
      formVisibleDown2: false,
      optionsModul2: [{
        key: 'sku_goods_name',
        label: 'SKU商品编码'
      },
      {
        key: 'name_ch',
        label: 'Product Name商品名称'
      },
      {
        key: 'quantity_purchased',
        label: 'Quantity数量'
      },
      {
        key: 'shipping_name',
        label: 'ExpressCorp快递公司'
      }
      ],
      optionsModul: [{
        key: 'invoice_no',
        label: 'BILLNO'
      },
      {
        key: 'shipping_code',
        label: 'TRACKINGNUMBER'
      },
      {
        key: 'shipping_name',
        label: 'EXPRESSCORP'
      },
      {
        key: 'sku_import',
        label: 'SKU'
      },
      {
        key: 'code_goods',
        label: 'SKU_ALL'
      }, {
        key: 'name_ch',
        label: 'SKUNAME'
      },
      {
        key: 'platform_no',
        label: 'ORDERID'
      },
      {
        key: 'shop_name',
        label: 'SHOPNAME'
      },
      {
        key: 'vi_name',
        label: 'WHNAME'
      },
      {
        key: 'en_name',
        label: 'SENDWHNAME'
      },
      {
        key: 'length_AS_total',
        label: 'TOTALLENGHT'
      },
      {
        key: 'width_AS_total',
        label: 'TOTALWIDTH'
      },
      {
        key: 'height_AS_total',
        label: 'TOTALHEIGHT'
      },
      {
        key: 'weight_AS_total',
        label: 'TOTALWEIGHT'
      },
      {
        key: 'number',
        label: 'QTY'
      },
      {
        key: 'address_name',
        label: 'BUYERNAME'
      },
      {
        key: 'address_phone',
        label: 'BUYERPHONE'
      },
      {
        key: 'address_street1',
        label: 'BUYERADDRESS'
      },
      {
        key: 'address_email',
        label: 'BUYEREMAIL'
      },
      {
        key: 'address_cityname',
        label: 'BUYERCITY'
      },
      {
        key: 'address_stateorprovince',
        label: 'BUYERSTATE'
      },
      {
        key: 'address_postalcode',
        label: 'BUYERZIP'
      },
      {
        key: 'address_country_name',
        label: 'BUYERCOUNTY'
      },
      {
        key: 'send_at_text',
        label: 'CDATE'
      }
      ],
      titel: '',
      componentName: 'DeliveryOrder',
      title: '发货单详情',
      loadingFaceSheet: false,
      urlImage: '',
      urlImages: [],
      zipData: '',
      id: '',
      formVisibleWlmd: false,
      formVisibleInfo: false,
      isbtn: false,
      formName: 'ruform',
      formVisibleWl: false,
      formLabelWidth: '150px',
      formFieldsData: {
        type: ''
      },
      rules: {
        type: [{
          required: true,
          message: '请选择物流公司',
          trigger: 'blur'
        }]
      },
      rules1: {
        type: [{
          required: true,
          message: '请选择物流类型',
          trigger: 'blur'
        }]
      },
      companyOption: [{
        label: 'ups',
        value: '1'
      }],
      orderId: '',
      formVisible: false,
      url: '/deliveryOrder',
      queryParam: {
        // 1-待发货（订单没有转为发货单时的状态）2-已发货（订单已经转发货单时的状态）
        // 3-运输中（订单对应的发货单打印物流面单后的状态）4-配送中（订单对应的发货单物流在配送中状态）5-已收货（订单对应的发货单物流单用户已收货）【可选】
        // delivery_state: '',
        delivery_type: '1', // 判断订单是否打印发货单1-未打印;2；打印【*必带参数】
        // service_type: '1', // 1-发货单号/2-订单编号/3-实体仓库/4-虚拟仓库/5-平台订单编号/6-店铺名称/7-平台名称【可选】
        // value: '', // 选择对应的查询服务的值【仓库-店铺-平台 输入均是名称】【可选】
        logistics_status: '1', // 1-成功发货订单，2-异常发货订单
        invoice_no: '',
        platform_no: '',
        order_no: '',
        deliver_type: '0',
        datePrint: [],
        limit: 50
      },
      fiftyLimit: 50,
      delivery_tabs: '1',
      selectType: 0,
      defaultQueryParam: ['logistics_status', 'delivery_type', 'deliver_type'],
      orderStatus: {
        1: '待发货',
        2: '待打印发货单',
        3: '运输中',
        4: '配送中',
        5: '已收货',
        6: '作废'
      },
      selectedList: [],
      selectedCodesNew: []
    }
  },
  computed: {
    downLoadParam() {
      const params = {}
      const object = this.queryParam
      for (const key in object) {
        if (Object.hasOwnProperty.call(object, key)) {
          const element = object[key]
          params[key] = element
        }
      }
      return params
    }
  },
  created() {
    lforwarderData().then((data) => {
      let uspsId = ''
      this.companyOption = data.map((arr) => {
        arr.value = arr.id + ',' + arr.name
        arr.ids = arr.id
        if (arr.name.toUpperCase() === 'USPS') {
          uspsId = arr.id + ''
        }
        return arr
      }).filter((item) => {
        return item.name !== 'USPS'
      })
      this.companyOption = this.companyOption.concat([{
        name: 'USPS_Cubic_PM',
        id: uspsId,
        ids: uspsId,
        value: uspsId + ',USPS_Cubic_PM'
      },
      {
        name: 'USPS_FCM',
        id: uspsId + 'USPS_FCM',
        ids: uspsId,
        value: uspsId + ',USPS_FCM'
      }
      ])
    })
  },
  methods: {
    // 管理员批量作废  delOrderPrinted
    delOrderPrinted(id, orderNo, type) {
      let typeText = ''
      if (type === '1') {
        typeText = `确认要作废发货单${orderNo}？`
      } else {
        typeText = `确认要修改发货单${orderNo}物流状态为收货？`
      }
      this.$confirm(`${typeText}`, '提示', {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$http.post(`/delOrderPrinted/${id}`, { type: type }).then((res) => {
          if (res.code === 10000) {
            this.$message.success(res.message)
            this.handleSearch()
          }
        }).catch(() => {

        })
      }).catch(() => { })
    },
    // 选择发货类型
    selsectType(item) {
      const vm = this
      vm.shipping_id = item.ids
      vm.selectedCodesNew = []
      switch (item.name) {
        case 'USPS_Cubic_PM':
          var list = this.data.filter((arr) => {
            return this.selectedCodes.includes(arr.invoice_no) && (arr.weight_AS_total <= 20)
          })
          vm.selectedCodesNew = list.map((arr) => {
            return arr.invoice_no
          })
          break
        case 'USPS_FCM':
          var list1 = this.data.filter((arr) => {
            return this.selectedCodes.includes(arr.invoice_no) && (arr.weight_AS_total <= 1)
          })
          vm.selectedCodesNew = list1.map((arr) => {
            return arr.invoice_no
          })
          break
        case 'UPS':
          vm.selectedCodesNew = vm.selectedCodes
          break
        default:
          break
      }
    },
    // 批量确认收货
    batchThridOrderDeliver() {
      const vm = this
      const list = this.data.filter((arr) => {
        return this.selectedIds.includes(arr.id) && arr.logistics_type === 2 && arr.shipping_code !== '' &&
          (arr.delivery_state !== 5) && arr.delivery_state !== 6
      })
      const ids = list.map((arr) => {
        return arr.id
      })
      vm.selectedCodes = list.map((arr) => {
        return arr.invoice_no
      })
      vm.list = vm.selectedCodes.join('</br>')
      if (vm.selectedCodes && vm.selectedCodes.length < 1) {
        this.$message.info('选择订单没有可确认收货的订单')
        return false
      }
      this.$confirm(`<div>确认发货单批量收货<p style="max-height: 400px;overflow-y: auto;">${vm.list}</p>？<div>`, '提示', {
        dangerouslyUseHTMLString: true,
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$http.post(`/deliveryOrders/batchThridOrderDeliver`, {
          ids: ids
        }).then((res) => {
          if (res.code === 10000) {
            this.$message.success('发货单确认收货成功')
            this.handleSearch()
          }
        }).catch(() => {
          this.isbtn = false
        })
      })
    },
    // 批量确认发货单
    confirmDeliverBatch() {
      const vm = this
      const list = this.data.filter((arr) => {
        return this.selectedIds.includes(arr.id) && arr.status === 0
      })
      const ids = list.map((arr) => {
        return arr.id
      })
      vm.selectedCodes = list.map((arr) => {
        return arr.invoice_no
      })
      vm.list = vm.selectedCodes.join('</br>')
      if (vm.selectedCodes && vm.selectedCodes.length < 1) {
        this.$message.info('选择订单没有需要确认发货单的订单')
        return false
      }
      this.$confirm(`<div>确认发货单<p style="max-height: 400px;overflow-y: auto;">${vm.list}</p>？<div>`, '提示', {
        dangerouslyUseHTMLString: true,
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$http.post(`/deliveryOrders/confirmDeliverBatch`, {
          ids: ids
        }).then((res) => {
          if (res.code === 10000) {
            this.$message.success('发货单确认成功')
            this.handleSearch()
          }
        }).catch(() => {
          this.isbtn = false
        })
      })
    },
    // 同步物流信息 orderSynchronous
    orderSynchronous() {
      const vm = this
      const list = this.data.filter((arr) => {
        return this.selectedIds.includes(arr.id) && (arr.delivery_state !== 5 && arr.delivery_state !== 6) &&
          arr.order_type_source === 1 && arr.shipping_code !== '' && arr
            .shop_basics_id !== '' && (arr.order_type === 0 || arr.order_type === 4)
      })
      const ids = list.map((arr) => {
        return arr.id
      })
      vm.selectedCodes = list.map((arr) => {
        return arr.invoice_no
      })
      vm.list = vm.selectedCodes.join('</br>')
      if (vm.selectedCodes && vm.selectedCodes.length < 1) {
        this.$message.info('选择订单没有可同步的订单')
        return false
      }
      // <p style="max-height: 400px;overflow-y: auto;">
      this.$confirm(`<div>确认同步发货单<p style="max-height: 400px;overflow-y: auto;">${vm.list}</p>物流信息？<div>`, '提示', {
        dangerouslyUseHTMLString: true,
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$http1.post(`/deliveryOrders/orderSynchronous`, {
          ids: ids
        }).then((res) => {
          if (res.code === 10000) {
            this.$message.success('同步发货单成功')
            // 成功数量
            const successNumber = res.data.success ? res.data.success.length : 0
            // 失败数量
            const emptyNumber = res.data.fail ? res.data.fail.length : 0
            this.$notify.info({
              title: '同步结果',
              dangerouslyUseHTMLString: true,
              message: `<div>同步成功${successNumber}个，同步失败数量${emptyNumber}个</div><div style="word-wrap: break-word;word-break: break-all;">
              失败提示：${res.data.fail ? res.data.fail : ''}</div>`,
              duration: 0
            })
            this.handleSearch()
          }
        }).catch(() => {
          this.isbtn = false
        })
      })
    },
    // 作废
    viodButtom(data) {
      this.$confirm(`确认作废发货单${data.invoice_no}`, '提示', {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$http.post(`/deliveryOrders/voidOrder/${data.id}`).then((res) => {
          if (res.code === 10000) {
            this.$message.success('发货单作废成功')
            this.handleSearch()
          }
        }).catch(() => {
          this.isbtn = false
        })
      })
    },
    setLogisticsType(data) {
      this.selectedIds = [data.id]
      this.setLogisticsTypeMore()
    },
    // 设置发货类型批量
    setLogisticsTypeMore() {
      const vm = this
      const list = this.data.filter((arr) => {
        return this.selectedIds.includes(arr.id) && arr.shipping_code === ''
      })
      const ids = list.map((arr) => {
        return arr.id
      })
      vm.selectedCodes = list.map((arr) => {
        return arr.invoice_no
      })
      if (vm.selectedCodes && vm.selectedCodes.length < 1) {
        this.$message.info('选择订单没有可设置发货类型')
        return false
      }
      vm.idsLogistics = ids
      vm.formVisibleWLogistics = true
    },
    // 第三方获取物流单号
    getLogisticsThrid() {
      this.selectedCodes = []
      this.selectedCodesNew = []
      this.formFieldsData.type = ''
      const list = this.data.filter((arr) => {
        return this.selectedIds.includes(arr.id) && arr.delivery_state === 1 && arr.status === 1 && arr
          .logistics_type === 1
      })
      const orderNoData = list.map((arr) => {
        return arr.invoice_no
      })
      if (orderNoData && orderNoData.length < 1) {
        this.$message.info('选择订单没有可获取物流单号')
        return false
      }
      this.selectedCodes = orderNoData
      this.formVisibleWl = true
    },
    // 获取物流单号
    getLogistics() {
      this.selectedCodes = []
      this.selectedCodesNew = []
      this.formFieldsData.type = ''
      const list = this.data.filter((arr) => {
        return this.selectedIds.includes(arr.id) && arr.delivery_state === 1 && arr.status === 1
      })
      const orderNoData = list.map((arr) => {
        return arr.invoice_no
      })
      if (orderNoData && orderNoData.length < 1) {
        this.$message.info('选择订单没有可获取物流单号')
        return false
      }
      this.selectedCodes = orderNoData
      this.formFieldsData.type = ''
      this.selectedCodesNew = []
      this.formVisibleWl = true
    },
    // 批量打印
    deliveryGetLabelMore(type) {
      this.shippingType = type
      if (this.shippingType === 'UPS') {
        const list = this.data.filter((arr) => {
          return this.selectedIds.includes(arr.id) && arr.delivery_state !== 1 && arr.delivery_state !== 5 && arr
            .status === 1 && arr.logistics_type === 1 && arr.shipping_name === 'UPS'
        })
        const orderNoData = list.map((arr) => {
          return arr.id
        })
        if (orderNoData && orderNoData.length < 1) {
          this.$message.info('选择订单没有可打印订单')
          return false
        }
        this.formVisibleWlmd = true
        this.loadingFaceSheet = true
        this.$http1
          .post(`/deliveryGetLabel`, {
            deliver_id: orderNoData
          })
          .then((res) => {
            // if(res.data.length<=1){
            //   this.urlImage = res.data[0];
            // }else{
            //   this.urlImages = res.data;
            // }
            this.urlImages = res.data.images
            this.pdfData = res.data.pdf
            this.zipData = res.data.zip
            this.loadingFaceSheet = false
          })
          .catch(() => {
            this.loadingFaceSheet = false
          })
      } else {
        const list = this.data.filter((arr) => {
          return this.selectedIds.includes(arr.id) && arr.delivery_state !== 1 && arr.delivery_state !== 5 && arr
            .status === 1 && arr.logistics_type === 1 && arr.shipping_name !== 'UPS'
        })
        const orderNoData = list.map((arr) => {
          return arr.id
        })
        if (orderNoData && orderNoData.length < 1) {
          this.$message.info('选择订单没有可打印订单')
          return false
        }
        this.formVisibleWlmd = true
        this.loadingFaceSheet = true
        this.$http1
          .post(`/deliveryGetLabelAll`, {
            deliver_id: orderNoData
          })
          .then((res) => {
            // if(res.data.length<=1){
            //   this.urlImage = res.data[0];
            // }else{
            //   this.urlImages = res.data;
            // }
            this.urlImages = res.data.images
            this.pdfData = res.data.pdf
            this.zipData = res.data.zip
            this.loadingFaceSheet = false
          })
          .catch(() => {
            this.loadingFaceSheet = false
          })
      }
    },
    // 保存pdf
    savePdf() {
      if (this.pdfData) {
        downloadUrl(this.pdfData)
      }
    },
    savePdf2() {
      if (!this.urlImages.length) {
        return
      }
      if (this.pdfData) {
        downloadUrl(this.pdfData)
      }
    },
    submitFormLogistics(formName) {
      const vm = this
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.isbtnLogistics = true
          const {
            type
          } = this.ruleForm
          const data = {
            type: type,
            ids: this.idsLogistics
          }
          this.$http
            .post(`/deliveryOrders/updateLogisticsType`, data)
            .then((res) => {
              vm.$message.success('设置成功')
              vm.handleSearch()
              vm.handleCancelLogistics()
              this.isbtnLogistics = false
            })
            .catch(() => {
              this.isbtnLogistics = false
            })
        } else {
          return false
        }
      })
    },
    handleCancelLogistics() {
      const vm = this
      vm.formVisibleWLogistics = false
    },
    // 下载
    downLoad() {
      const vm = this
      vm.$http
        .get('/deliveryOrders/template', {
          responseType: 'blob'
        })
        .then((res) => {
          downloadStream(res, '第三方物流导入模板.xlsx')
        })
    },
    handleClick(tab, event) {
      const vm = this
      if (this.delivery_tabs === '3') {
        this.queryParam.delivery_type = ''
        this.queryParam.deliver_type = '1'
      } else {
        this.queryParam.delivery_type = this.delivery_tabs
        this.queryParam.deliver_type = '0'
      }
      if (this.delivery_tabs === '2') {
        vm.queryParam.datePrint = [
          vm.$moment().startOf('day').format('yyyy-MM-DD HH:mm:ss'),
          vm.$moment().endOf('day').format('yyyy-MM-DD HH:mm:ss')
        ]
        // vm.queryParam.datePrint = [new Date(2000, 10, 10, 10, 10), new Date(2000, 10, 11, 10, 10)]
      } else {
        vm.queryParam.datePrint = []
        vm.queryParam.start_print = ''
        vm.queryParam.end_print = ''
      }
      this.handleSearch()
    },
    beforeSearch() {
      const vm = this
      vm.queryParam.start_at = ''
      vm.queryParam.end_at = ''
      vm.queryParam.start_print = ''
      vm.queryParam.end_print = ''
      vm.queryParam.shop_ids = ''
      if (vm.queryParam.shop_id && vm.queryParam.shop_id.length > 0) {
        vm.queryParam.shop_ids = vm.queryParam.shop_id.join(',')
      }
      // datePrint
      if (vm.queryParam.datePrint && vm.queryParam.datePrint.length > 0) {
        vm.queryParam.start_print = vm.queryParam.datePrint[0]
        vm.queryParam.end_print = vm.queryParam.datePrint[1]
      }
      // 生成日期转化
      if (vm.queryParam.dateCreat && vm.queryParam.dateCreat.length > 0) {
        vm.queryParam.start_at = vm.queryParam.dateCreat[0]
        vm.queryParam.end_at = vm.queryParam.dateCreat[1]
      }
      if (vm.queryParam.category_ids && vm.queryParam.category_ids.length > 0) {
        // vm.queryParam.category_id = vm.queryParam.category_ids.pop()
        const arr = vm.queryParam.category_ids
        vm.queryParam.category_id = arr[arr.length - 1]
      } else {
        vm.queryParam.category_id = ''
      }
    },
    // 下载面单 submitFormBatchDown
    submitFormBatchDown() {
      downloadxlsx(this.zipData)
    },
    // 预览打印面单
    submitFormPrint() {
      const list = this.data.filter((arr) => {
        return this.selectedIds.includes(arr.id) && arr.delivery_state !== 1 && arr.delivery_state !== 5 && arr
          .status === 1 && arr.logistics_type === 1
      })
      const orderNoData = list.map((arr) => {
        return arr.id
      })
      const id = this.urlImage ? [this.id] : orderNoData
      this.isbtn = true
      this.$http
        .post(`/deliveryPrintLabel`, {
          deliver_id: id
        })
        .then((res) => {
          if (res.code === 10000) {
            if (this.urlImage) {
              this.savePdf()
            } else {
              this.savePdf2()
            }
            // this.$message.success('面单打印成功')
            this.isbtn = false
            this.handleCancelWlmd()
            this.handleSearch()
          }
        })
        .catch(() => {
          this.isbtn = false
        })
    },
    // 获取面单
    deliveryGetLabel(item) {
      const id = item.id
      this.id = id
      this.formVisibleWlmd = true
      this.loadingFaceSheet = true
      if (item.shipping_name.toUpperCase() === 'UPS') {
        this.shippingType = 'UPS'
        this.$http1
          .post(`/deliveryGetLabel`, {
            deliver_id: [id]
          })
          .then((res) => {
            this.urlImage = res.data.images[0]
            this.pdfData = res.data.pdf
            this.zipData = res.data.zip
            this.loadingFaceSheet = false
          })
          .catch(() => {
            this.loadingFaceSheet = false
          })
      } else {
        this.shippingType = 'USPS'
        this.$http1
          .post(`/deliveryGetLabelAll`, {
            deliver_id: [id]
          })
          .then((res) => {
            this.urlImage = res.data.images[0]
            this.pdfData = res.data.pdf
            this.zipData = res.data.zip
            this.loadingFaceSheet = false
          })
          .catch(() => {
            this.loadingFaceSheet = false
          })
      }
    },
    handleCancelWlmd() {
      this.id = ''
      this.urlImage = ''
      this.urlImages = []
      this.pdfData = ''
      this.zipData = ''
      this.formVisibleWlmd = false
    },
    // 获取运单号
    deliveryUps() {
      if (this.selectedCodesNew.length < 1) {
        this.$message.info('暂无符合条件发货单')
        return false
      }
      // 判断是否是UPS
      //   if ((this.formFieldsData.type.name).toUpperCase() !== 'UPS') {
      //     this.$message.info('物流目前只支持UPS')
      //     return false
      //   }
      this.$refs[this.formName].validate((valid) => {
        if (valid) {
          this.isbtn = true
          const data = {}
          data.invoice_no = this.selectedCodesNew
          // data.shipping_id = this.formFieldsData.type.id
          data.shipping_id = this.shipping_id
          data.shipping_name = this.formFieldsData.type.name
          this.$http1
            .post(`/delivery`, data)
            .then((res) => {
              if (res.code === 10000) {
                this.$message.success('获取运单号成功')
                this.isbtn = false
                this.handleCancelWl()
                this.resetFormFields()
                this.handleSearch()
              }
            })
            .catch(() => {
              this.isbtn = false
            })
        } else {
          return false
        }
      })
    },
    handleCancelWl() {
      this.formVisibleWl = false
    }
    // 设置禁止选择项
    // checkSelectable(row, index) {
    //   if (this.delivery_tabs === '1') {
    //     if (!this.selectType) {
    //       return true
    //     } else {
    //       return row.delivery_state === this.selectType
    //     }
    //   } else if (this.delivery_tabs === '3') {
    //     if (
    //       this.selectTypeLoginstics === -1 &&
    //       row.shipping_code === '' &&
    //       row.status === 1
    //     ) {
    //       return true
    //     } else {
    //       return (
    //         row.shipping_code === '' &&
    //         row.logistics_type === this.selectTypeLoginstics
    //       )
    //     }
    //   }
    // }
  }
}

</script>

<style lang="scss" scoped>
.imag_rote {
  height: 240px;
  width: 420px;
  transform: rotate(90deg) !important;
  -ms-transform: rotate(90deg);
  /* Internet Explorer */
  -moz-transform: rotate(90deg) !important;
  /* Firefox */
  -webkit-transform: rotate(90deg) !important;
  /* Safari 和 Chrome */
  -o-transform: rotate(90deg);
  /* Opera */
  position: absolute;
  top: 73px;
  left: 146px;
}
.imag_rote_usps {
  width: 240px;
  height: 360px;
  // transform: rotate(90deg) !important;
  // -ms-transform: rotate(90deg);
  // /* Internet Explorer */
  // -moz-transform: rotate(90deg) !important;
  // /* Firefox */
  // -webkit-transform: rotate(90deg) !important;
  // /* Safari 和 Chrome */
  // -o-transform: rotate(90deg);
  // /* Opera */
  // position: absolute;
  // top: 73px;
  // left: 146px;
}

.imag_rotes {
  height: 240px;
  width: 420px;
  transform: rotate(90deg) !important;
  -ms-transform: rotate(90deg);
  /* Internet Explorer */
  -moz-transform: rotate(90deg) !important;
  /* Firefox */
  -webkit-transform: rotate(90deg) !important;
  /* Safari 和 Chrome */
  -o-transform: rotate(90deg);
  /* Opera */
  position: absolute;
  top: 100px;
  left: 146px;
}

/*去除页眉页脚*/
@page {
  size: auto;
  /* auto is the initial value */
  margin: 3mm;
  /* this affects the margin in the printer settings */
}

html {
  background-color: #ffffff;
  margin: 0;
  /* this affects the margin on the html before sending to printer */
}

body {
  border: solid 1px blue;
  margin: 10mm 15mm 10mm 15mm;
  /* margin you want for the content */
}
</style>
